package view;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;

import javax.swing.WindowConstants;
import org.jdesktop.application.Action;
import org.jdesktop.application.Application;
import org.jdesktop.application.ApplicationActionMap;
import javax.swing.SwingUtilities;


public class LocalBusqueda extends javax.swing.JPanel {
	private JLabel jLabelLocalBusqueda;
	private JComboBox jComboBoxLocalLista;
	private JButton jButtonLocalAceptar;
	private JButton jButtonLocalCancelar;
	private AbstractAction abstractActionLocalAceptar;
	private static LocalBusqueda frameLocalBusquedaInstancia;
	private LocalModificacion frameLocalModificacion;

	public static LocalBusqueda getInstancia(){
		if(frameLocalBusquedaInstancia==null){
			frameLocalBusquedaInstancia=new LocalBusqueda();
		}
		return frameLocalBusquedaInstancia;
	}
	
	public LocalBusqueda() {
		super();
		this.frameLocalModificacion=LocalModificacion.getInstancia();
		this.frameLocalModificacion.setVisible(false);
		initGUI();
	}
	
	private void initGUI() {
		try {
			{
				jLabelLocalBusqueda = new JLabel();
				this.add(jLabelLocalBusqueda);
				jLabelLocalBusqueda.setText("Seleccione Local que desea modificar:  ");
				jLabelLocalBusqueda.setBounds(43, 44, 229, 14);
			}
			{
				ComboBoxModel jComboBoxLocalListaModel = 
					new DefaultComboBoxModel(
							new String[] { "Item One", "Item Two" });
				jComboBoxLocalLista = new JComboBox();
				this.add(jComboBoxLocalLista);
				jComboBoxLocalLista.setModel(jComboBoxLocalListaModel);
				jComboBoxLocalLista.setBounds(290, 41, 68, 21);
			}
			{
				jButtonLocalAceptar = new JButton();
				this.add(jButtonLocalAceptar);
				jButtonLocalAceptar.setText("Aceptar");
				jButtonLocalAceptar.setBounds(91, 90, 96, 21);
				jButtonLocalAceptar.setAction(getAbstractActionLocalAceptar());
			}
			{
				jButtonLocalCancelar = new JButton();
				this.add(jButtonLocalCancelar);
				jButtonLocalCancelar.setText("Cancelar");
				jButtonLocalCancelar.setBounds(221, 90, 100, 21);
				jButtonLocalCancelar.setAction(getAppActionMap().get("actionCancelar"));
			}
			this.setSize(393, 153);
			this.setLayout(null);
			Application.getInstance().getContext().getResourceMap(getClass()).injectComponents(this);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private AbstractAction getAbstractActionLocalAceptar() {
		if(abstractActionLocalAceptar == null) {
			abstractActionLocalAceptar = new AbstractAction("Aceptar", null) {
				public void actionPerformed(ActionEvent evt) {
					//TO DO
					frameLocalModificacion.setVisible(true);
					frameLocalBusquedaInstancia.setVisible(false);
				}
			};
		}
		return abstractActionLocalAceptar;
	}
	
	private ApplicationActionMap getAppActionMap() {
		return Application.getInstance().getContext().getActionMap(this);
	}
	
	@Action
	public void actionCancelar() {
		frameLocalBusquedaInstancia.setVisible(false);
	}

}
